Skip to contents
library(ggoncoplot)
library(dplyr, warn.conflicts = FALSE)

Input Data

The input for ggoncoplot is a data.frame with 1 row per mutation. data.frame must contain columns describing the following:

  • Gene Symbol

  • Sample Identifier

  • (optional) mutation type

  • (optional) tooltip (character string: what we show on mouse hover over a particular mutation)

These columns can be in any order, and named anything. You define the mapping of your input dataset columns to the required features in the call to ggoncoplot

Minimal Example


# TCGA GBM dataset from TCGAmuations package
gbm_csv <- system.file(package='ggoncoplot', "testdata/GBM_tcgamutations_mc3_maf.csv.gz")
gbm_df <- read.csv(file = gbm_csv, header=TRUE)

gbm_df |> 
  ggoncoplot(
    col_genes = 'Hugo_Symbol', 
    col_samples = 'Tumor_Sample_Barcode'
  )

Colour by mutation type

Colour by mutation by specifying col_mutation_type


# TCGA GBM dataset from TCGAmuations package
gbm_csv <- system.file(package='ggoncoplot', "testdata/GBM_tcgamutations_mc3_maf.csv.gz")
gbm_df <- read.csv(file = gbm_csv, header=TRUE)

gbm_df |> 
  ggoncoplot(
    col_genes = 'Hugo_Symbol', 
    col_samples = 'Tumor_Sample_Barcode', 
    col_mutation_type = 'Variant_Classification'
  )
#> 
#> ── Identify Class ──────────────────────────────────────────────────────────────
#>  Found 7 unique mutation types in input set
#>  0/7 mutation types were valid SO terms
#>  7/7 mutation types were valid MAF terms
#>  Mutation Types are described using valid MAF terms ... using MAF palete

Control which genes are shown

Show top [n] Genes

Show the 4 most frequently mutated genes using topn argument

gbm_df |> 
  ggoncoplot(
    col_genes = 'Hugo_Symbol', 
    col_samples = 'Tumor_Sample_Barcode', 
    col_mutation_type = 'Variant_Classification', 
    topn = 4
  )
#> 
#> ── Identify Class ──────────────────────────────────────────────────────────────
#>  Found 7 unique mutation types in input set
#>  0/7 mutation types were valid SO terms
#>  7/7 mutation types were valid MAF terms
#>  Mutation Types are described using valid MAF terms ... using MAF palete

Exclude Specific Genes

Use the genes_to_ignore argument to filter out specific genes, such as TTN and MUC16.

gbm_df |> 
  ggoncoplot(
    col_genes = 'Hugo_Symbol', 
    col_samples = 'Tumor_Sample_Barcode', 
    col_mutation_type = 'Variant_Classification', 
    topn = 10,
    genes_to_ignore = c("TTN", "MUC16")
  )
#> 
#> ── Identify Class ──────────────────────────────────────────────────────────────
#>  Found 9 unique mutation types in input set
#>  0/9 mutation types were valid SO terms
#>  9/9 mutation types were valid MAF terms
#>  Mutation Types are described using valid MAF terms ... using MAF palete

You can use packages like somaticflags to get lists of genes you might want to filter out.

Gene Subset

lets only show TP53 and TERT

gbm_df |> 
  ggoncoplot(
    col_genes = 'Hugo_Symbol', 
    col_samples = 'Tumor_Sample_Barcode', 
    col_mutation_type = 'Variant_Classification', 
    genes_to_include = c('TP53', 'TERT'),
  )
#> 
#> ── Identify Class ──────────────────────────────────────────────────────────────
#>  Found 6 unique mutation types in input set
#>  0/6 mutation types were valid SO terms
#>  6/6 mutation types were valid MAF terms
#>  Mutation Types are described using valid MAF terms ... using MAF palete

Control what samples are shown

The show_all_samples argument will add samples that don’t have mutations in the selected genes to the plot.

gbm_df |> 
  ggoncoplot(
    col_genes = 'Hugo_Symbol', 
    col_samples = 'Tumor_Sample_Barcode', 
    col_mutation_type = 'Variant_Classification', 
    show_all_samples = TRUE
  )
#> 
#> ── Identify Class ──────────────────────────────────────────────────────────────
#>  Found 7 unique mutation types in input set
#>  0/7 mutation types were valid SO terms
#>  7/7 mutation types were valid MAF terms
#>  Mutation Types are described using valid MAF terms ... using MAF palete

Note that if you supply a metadata table, by default samples lacking ANY mutations at all will still not be shown. You can include these samples by setting metadata_require_mutations = FALSE but this isn’t recommended unless you’re sure the sample truly has no mutations at all in the dataframe.

Custom Tooltip

Use the col_tooltip argument to indicate which column of your input dataframe should be used as a custom tooltip.

gbm_df |> 
  mutate(tooltip = paste0(Chromosome, ":", Start_Position, " ", Reference_Allele, ">", Tumor_Seq_Allele2)) |>
  ggoncoplot(
    col_genes = 'Hugo_Symbol', 
    col_samples = 'Tumor_Sample_Barcode', 
    col_mutation_type = 'Variant_Classification', 
    col_tooltip = 'tooltip' # We'll specify a custom tooltip based on our new 'tooltip' column
  )
#> 
#> ── Identify Class ──────────────────────────────────────────────────────────────
#>  Found 7 unique mutation types in input set
#>  0/7 mutation types were valid SO terms
#>  7/7 mutation types were valid MAF terms
#>  Mutation Types are described using valid MAF terms ... using MAF palete

Note tooltips are html, so if you want to insert a break, just paste in <br>.

Similarly, if you want to make text in the tooltip bold, try "<b>text_to_bold<\b>".

Note that where a single sample has multiple mutations in a gene, are represented as one tile in oncoplot, tooltip for each mutation are shown (newline delimited).

Add margin plots

Gene Barplot

How many samples have mutations in each Gene (optionally coloured by mutation type)

gbm_df |> 
  ggoncoplot(
    col_genes = 'Hugo_Symbol', 
    col_samples = 'Tumor_Sample_Barcode', 
    col_mutation_type = 'Variant_Classification',
    draw_gene_barplot = TRUE
  )
#> 
#> ── Identify Class ──────────────────────────────────────────────────────────────
#>  Found 7 unique mutation types in input set
#>  0/7 mutation types were valid SO terms
#>  7/7 mutation types were valid MAF terms
#>  Mutation Types are described using valid MAF terms ... using MAF palete

Tumour Mutation Burden

How many mutations (total) are in each sample

Not implemented yet: coming soon (https://github.com/selkamand/ggoncoplot/issues/30)

Static Plots

gbm_df |> 
  ggoncoplot(
    col_genes = 'Hugo_Symbol', 
    col_samples = 'Tumor_Sample_Barcode', 
    col_mutation_type = 'Variant_Classification', 
    interactive = FALSE
  )
#> 
#> ── Identify Class ──────────────────────────────────────────────────────────────
#>  Found 7 unique mutation types in input set
#>  0/7 mutation types were valid SO terms
#>  7/7 mutation types were valid MAF terms
#>  Mutation Types are described using valid MAF terms ... using MAF palete